<style>
    .res_section1 {
        padding: 10px;
    }

    .res_section1 .all_1 .dhh {
        background: url("__PUBLIC__/home/images/v10_a19.png");
        background-size: 100% 100%;
        padding: 10px;
    }

    .res_section1 .all_1 .f1 {
        border-bottom: none;
    }

    .res_section1 .all_1 .s1 {
        display: block !important;
        margin-bottom: 10px;
    }

    .res_section1 .all_1 .f1 input {
        float: inherit !important;
        width: 100% !important;
        text-align: left !important;
        background: #292f71 !important;
        text-indent: 0.5rem;
        padding: 3px 0px;
    }

    .adk_section1 {
        padding: 10px;
    }

    .adk_section1 .f2 {
        margin-top: 15px;
    }

    .adk_section1 .f2 li {
        float: left;
        width: 50%;
    }

    .adk_section1 .f2 li .ak {
        width: 90%;
        margin: 0 auto;
    }

    .adk_section1 .f2 li .ak img {
        width: 100%;
        height: 100px;
    }

    .adk_section1 .f2 li .an {
        width: 90%;
        margin: 0 auto;
        margin-top: 20px;
        text-align: center;
    }

    .adk_section1 .f2 li .an button {
        width: 100%;
        color: #fff;
        border-radius: 5px;
        height: 40px;
        border: none;
        background: linear-gradient(to bottom, #00afe5, #0358e3);
    }

    .adk_section1 .f3 {
        margin-top: 25px;
    }

    .adk_section1 .f3 .k1 {
        margin-bottom: 15px;
        border-bottom: 1px solid #eee;
        padding-bottom: 10px;
    }

    .adk_section1 .f3 .k1 input {
        width: 60%;
        border: none;
        color: #000;
        margin-left: 10px;
        font-size: 0.9rem;
    }

    .adk_section1 .f4 {
        margin-top: 15px;
        font-size: 0.8rem;
    }

    .adk_section1 .f4 .p1 {
        color: #666;
    }

    .adk_section1 .f4 .p2 {
        color: #ff4546;
        margin-top: 5px;
    }

    .adk_section1 .sub {
        margin-top: 40px;
    }

    .adk_section1 .sub button {
        width: 100%;
        height: 45px;
        border: none;
        color: #fff;
        font-size: 1rem;
        border-radius: 5px;
        background: linear-gradient(to bottom, #00afe5, #0358e3);
    }
</style>
<div class="bg_fixed_v10_1"></div>
<div class="sectionY sectionY_tttt">
    <a href="{:url('User/index')}">
        <img src="__PUBLIC__/home/images/a4.png" alt="" class="a1">
    </a>
    <p class="p1">
        <span class="ppp_title">实名认证</span>
    </p>
</div>
<div class="kong1"></div>
<!-- <div class="res_section1" style="margin-top: 15px">
        <div class="all_1">
            <div class="dhh">
                <div class="f1">
                    <p class="s1 ">真实姓名：</p>
                    <input type="text" name='realname' value="{$userinfo.realname}" class="input1" placeholder="请填写真实姓名" autocomplete="off">
                </div>
                <div class="f1">
                    <span class="s1 ">证件号码：</span>
                    <input type="text" name='code' value="{$userinfo.selfcard}" class="input1" placeholder="请填写证件号码" autocomplete="off">
                </div>

                <div class="f1">
                    <span class="s1 ">紧急联系人：</span>
                    <input type="text" name='mustman' class="input1" value="{$userinfo.mustman}" placeholder="请输入紧急联系人电话" autocomplete="off">
                </div>
            </div>

            <div class="sub" style="padding: 20px 0px">
                <input type="submit" value="确认提交">
            </div>
        </div>
</div> -->
<div class="adk_section1">
    <form action="">
        <div class="f1">
            <p class="p1">请上传你的身份证照片</p>
        </div>
        <div class="f2 clearfix">
            <ul>
                <li>
                    <div class="ak">
                        <img id="imghead1" src="__PUBLIC__/home/images/am1.png" alt="">
                    </div>
                    <div class="an">
                        <button type="button" class="img_btn" data-id="1">点击上传</button>
                        <input type="file" id="file1" data-id="1" onchange="imgChange(this);"
                               style="width: 0; height: 0">
                    </div>
                </li>
                <li>
                    <div class="ak">
                        <img id="imghead2" src="__PUBLIC__/home/images/am4.png" alt="">
                    </div>
                    <div class="an">
                        <button type="button" class="img_btn" data-id="2">点击上传</button>
                        <input type="file" id="file2" data-id="2" onchange="imgChange(this);"
                               style="width: 0; height: 0">
                    </div>
                </li>
            </ul>
        </div>
        <div class="f3">
            <div class="k1">
                <span class="s1">真实姓名：</span>
                <input type="text" name='realname' value="{$userinfo.realname}" placeholder="请输入真实姓名">
            </div>
            <div class="k1">
                <span class="s1">身份证号：</span>
                <input type="text" name='code' value="{$userinfo.selfcard}" placeholder="请输入身份证号">
            </div>
            <div class="k1">
                <span class="s1">紧急联系人：</span>
                <input type="text" name='mustman' value="{$userinfo.mustman}" placeholder="请输入紧急联系人电话">
            </div>
        </div>
        <div class="f4">
            <p class="p1">大陆公民持有的本人有效二代身份证；要保证</p>
            <p class="p2">边框完整，字体清晰，亮度均匀；</p>
        </div>
        <div class="sub">
            <input type="hidden" id="upload_geturl1" value="">
            <input type="hidden" id="upload_geturl2" value="">
            <button type="button" id="ssu">提交认证</button>
        </div>
    </form>
</div>
<script type="text/javascript">
    var is_app = 0;
    try {
        is_app = android.getType();
    } catch (e) {
    }
    var site = 0;
    $(function () {
        $(".img_btn").click(function () {
            site = $(this).data("id");
            console.log(site);
            if (is_app == 1) {
                android.uploadImage(location.origin + "/home/Upload/appupimg.html");
            } else {
                $(this).siblings("input").click();
            }
        })
    })

    //安卓回调
    function setImage(img_url) {
        $("#imghead" + site).attr('src', img_url); // 修改img标签src属性值
        $("#upload_geturl" + site).val(img_url);
    }

    function imgChange(obj) {
        var docObj = $(obj).get(0);
        if (docObj.files && docObj.files[0]) {
            if (!/image\/\w+/.test(docObj.files[0].type)) {
                //图片文件的type值为image/png或image/jpg
                layer.msg("文件必须为图片！");
                return false;
            }
            var formData = new FormData();
            formData.append("files", docObj.files[0]);
            $.ajax({
                url: "{:url('Upload/upimg')}",
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                success: function (rs) {
                    rs = JSON.parse(rs);
                    if (rs.status == 0) {
                        setImage(rs.data)
                    } else {
                        layer.alert(rs.info, {shade: 0.2});
                        return false;
                    }
                },
                error: function () {
                    layer.msg('系统错误，请稍后重试');
                }
            });
        } else {
            layer.msg('请上传图片');
        }
        return true;
    }


    $(function () {
        /*重置密码*/
        $("#ssu").click(function () {
            var realname = $('input[name=realname]').val();
            var code = $('input[name=code]').val();
            var mustman = $('input[name=mustman]').val();
            var card_1 = $("#upload_geturl1").val();
            var card_2 = $("#upload_geturl2").val();
            if (realname == '') {
                layer.alert('请输入真实姓名！', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }
            var nameReg = /^[\u4E00-\u9FA5]{2,4}$/;
            if (!nameReg.test(realname)) {
                layer.alert('真实姓名格式错误，请检查！', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }

            if (code == '') {
                layer.alert('请输入身份证号！', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }
            var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if (!pattern.test(code)) {
                layer.alert('身份证号码格式错误，请检查！', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }
            if (mustman == '') {
                layer.alert('请输入紧急联系人电话!', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }
            if (!(/^1[3|4|5|7|8|9][0-9]\d{4,8}$/.test(mustman))) {
                layer.alert('紧急联系人手机号码错误!', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }
            if (card_1 == '') {
                layer.alert('请上传身份证正面!', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }

            if (card_2 == '') {
                layer.alert('请上传身份证背面!', {icon: 2, shade: 0.8, title: "错误提示:"});
                return false;
            }


            $.ajax({
                type: 'POST',
                url: "{:url('User/certification')}",
                dataType: "html",
                data: "realname=" + realname + "&selfcard=" + code + "&mustman=" + mustman + "&card_1=" + card_1 + "&card_2=" + card_2,
                success: function (res) {
                    var obj = JSON.parse(res);
                    console.log(obj);
                    if (obj.s == 10) {
                        layer.msg(obj.msg, {
                            shade: 0.6, time: 1000, end: function () {
                                window.location.href = window.location.href;
                            }
                        });
                    } else {
                        layer.alert(obj.msg, {shade: 0.2});
                        return false;
                    }
                },
                error: function () {
                    layer.alert('系统繁忙，请稍后再试！', {icon: 2, shade: 0.8, title: "错误提示:"});
                }
            });
        });

    });
</script>
